package com.crmfront.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.crmfront.util.UrlUtils;
import com.pojo.Customer;
import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("/customer")
public class CustomerController {

    @CrossOrigin
    @RequestMapping("/customerList")
    public String customerList(Model model) {

        String url = "http://localhost:8099/customer/customerList" ;
        String params = "" ;

        String result = UrlUtils.sendGet(url, params) ;

        JSONArray array = JSON.parseArray(result) ;
        List<Customer> customerList  = array.toJavaList(Customer.class) ;

        model.addAttribute("customerList", customerList) ;

        return "customer/customerList" ;
    }
}
